package stream;

import pojo.Person;

import java.util.stream.Stream;

public class StreamDistinct {
    public static void main(String[] args) {
//        Stream<Integer> stream= Stream.of(11,22,33,445,11,445);
//        Stream<Integer> distinct = stream.distinct();
//        //去重
//        distinct.forEach(System.out::println);
        Person p1 = new Person(101, "汪云飞");
        Person p2 = new Person(102, "feifei");
        Person p3 = new Person(103, "周雨晴");
        Person p4 = new Person(103, "周雨晴");

        /**
         * 在底层，是通过hashcode()和equals()方法判断两个对象是不是同一个对象
         * 通过重写equ als()和hashcode()方法，来判断两个对象是否是一样的
         */
        Stream<Person> p11 = Stream.of(p1, p2, p3, p4);
        p11.distinct().forEach(System.out::println);

    }
}
